/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var maxDepth = function (root) {
  let res = 0
  if (root === null) {
    return res
  }
  const empty = data => {
    return data === null || data === undefined
  }
  const getMaxDeep = (tree, max) => {
    max++
    res < max && (res = max)
    !empty(tree.left) && getMaxDeep(tree.left, max)
    !empty(tree.right) && getMaxDeep(tree.right, max)
  }
  getMaxDeep(root, 0)
  return res
}
